package cn.edu.xmu.datamining.tangzk.mralgos.pagerank;

import org.apache.hadoop.io.RawComparator;
import org.apache.hadoop.io.WritableComparator;

/**
 * only compare the first part when grouping keys.
 */
public class PageRankGrouper implements RawComparator<PageRankNodeKeyWritable> {

	private static int INT_LEN = Integer.SIZE / 8;

	@Override
	public int compare(PageRankNodeKeyWritable o1, PageRankNodeKeyWritable o2) {
		return o1.getId() - o2.getId();
	}

	@Override
	public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
		return WritableComparator
				.compareBytes(b1, s1, INT_LEN, b2, s2, INT_LEN);
	}

}
